package com.ashapo;

import java.util.HashMap;
import java.util.HashSet;

/**
 * 班级
 * @author Administrator
 */
public class Chapter {
	
	private String name;
	
	private String address;
	
	private HashMap<String, Student> students; 

	public Chapter() {
		this.students = new HashMap<>();
	}
	
	public Chapter(String name, String address){
		this.name = name;
		this.address = address;
		this.students = new HashMap<>();
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public HashMap<String, Student> getStudents() {
		return students;
	}
	
	public void addStudent(String id, Student student){
		this.students.put(id, student);
	}
	
	public boolean delStudent(String id){
		if(this.students.keySet().contains(id)){
			this.students.remove(id);
			return true;
		}else{
			return false;
		}
	}
	
	/**
	 * 判断是否存在学生
	 * @param std
	 * @return 
	 */
	public boolean hasStudent(Student std){
		if(this.students.containsValue(std)){
			return true;
		}else{
			return false;
		}
	}
	
	/**
	 * 判断集合中的学生是否都在成员内
	 * @param stds
	 * @return 
	 */
	public boolean hasStudents(HashSet<Student> stds){
		boolean all_has = true;
		for (Student std : stds) {
			if(!this.hasStudent(std)){
				all_has = false;
				break;
			}
		}
		return all_has;
	}
	
	/**
	 * 判断班级里是否有该学号的学生
	 * @param id 学号ID
	 * @return 
	 */
	public boolean hasStudentById(String id){
		return this.students.containsKey(id);
	}
}